{# This macro must be imported 'with context' from a pieces module #}
{# subclass. -Tom #}



{# bring in modals #}
{%- import "apostrophe-modal:macros.html" as modals -%}
{# bring in ui components #}
{% import 'apostrophe-ui:components/buttons.html' as buttons with context %}
{% import 'apostrophe-ui:components/dropdowns.html' as dropdowns with context %}
{% import 'apostrophe-ui:components/pills.html' as pills with context %}
{% import 'apostrophe-ui:components/fields.html' as fields with context %}

{# Maintained for bc. Newer templates call the module's createControls helper. #}
{%- macro createControls() -%}
  {{ dropdowns.base({
    label: 'More',
    items: [
      {label: 'Trash', action: 'trash'}
    ]}, 'button',
    {
      direction: 'down',
      class: 'arrow-down'
    }
  ) }}
  {{ buttons.minor('Cancel', { action: 'cancel' }) }}
  {{ buttons.major('Save ' + data.options.label, { action: 'save' }) }}
{% endmacro %}

{# Maintained for bc. Newer templates call the module's editControls helper. #}
{%- macro editControls() -%}
  {{ dropdowns.base({
    label: 'More',
    items: [
      {label: 'Versions', action: 'versions'},
      {label: 'Copy', action: 'copy'},
      {label: 'Trash', action: 'trash'}
    ]}, 'button',
    {
      direction: 'down',
      class: 'arrow-down'
    }
  ) }}
  {{ buttons.minor('Cancel', { action: 'cancel' }) }}
  {{ buttons.major('Save ' + data.options.label, { action: 'save' }) }}

{%- endmacro -%}

{# Maintained for bc. Newer templates call the module's managerControls or #}
{# chooserControls helper, as appropriate. #}

{%- macro manageControls() -%}
  {% if data.chooser %}
    {{ buttons.minor('Cancel', { action: 'cancel' }) }}
    {# "New" is less ambiguous than "Add" when you're already *choosing* things. -Tom #}
    {% if data.options.insertViaUpload %}
      <input type="file" multiple name="files" style="display:none" data-apos-uploader-{{ data.options.name }} />
      {{ buttons.major('New ' + data.options.label, { action: 'upload-' + data.options.name }) }}
    {% else %}
      {{ buttons.major('New ' + data.options.label, { action: 'create-' + data.options.name }) }}
    {% endif %}
    {{ buttons.major('Save Choices', { action: 'save' }) }}
  {% else %}
    {# Technically it's "just" a cancel button but it's actually the most frequent action #}
    {# when you're just managing stuff. There is no risk of losing work. -Tom #}
    {{ buttons.minor('Finished', { action: 'cancel' }) }}
    {% if data.options.insertViaUpload %}
      <input type="file" multiple name="files" style="display:none" data-apos-uploader-{{ data.options.name }} />
      {{ buttons.major('Add ' + data.options.label, { action: 'upload-' + data.options.name }) }}
    {% else %}
      {{ buttons.major('Add ' + data.options.label, { action: 'create-' + data.options.name }) }}
    {% endif %}
  {% endif %}
{%- endmacro -%}


{%- macro filters(filters) -%}
  {#
    Normal cursor-driven filters
  #}
  <div class="apos-modal-filters-toggles">
    <div class="apos-modal-filters-wrapper apos-modal-filters-wrapper--left">
      <span class="apos-modal-filter apos-modal-filter--padded">
        {{ fields.checkbox('select-all') }}
      </span>
      {%- for filter in filters.options -%}
      <span class="apos-modal-filter">
        {%- if not apos.utils.isFalse(filter.label) -%}
        <label for="{{ filter.name }}">{{ filter.label or apos.utils.startCase(filter.name) }}</label>
        {%- endif -%} {%- if filter.multiple -%} {%- for chosen in filters.choices[filter.name] -%} {% set id = apos.utils.generateId()
        %}
        <label class="apos-modal-filter-selection" for="{{ id }}">
          <input type="checkbox" id="{{ id }}" name="{{ filter.name }}" value="{{ chosen }}" checked /> {{ apos.utils.find(filter.choices, 'value', chosen).label }}</label>
        {%- endfor -%} {{ fields.select(filter.name, apos.utils.concat([ { label: 'Choose One', value: '**CHOOSE**' } ], apos.utils.difference(filter.choices,
        filters.choices[filter.name], 'value')), '**CHOOSE**') }} {%- else -%} {{ fields.select(filter.name, apos.utils.concat([
        { label: filter.anyLabel or '—', value: "**ANY**" } ], filter.choices), filters.choices[filter.name]) }} {%- endif -%}
      </span>
      {%- endfor -%}
    </div>
      <div class="apos-modal-filters-wrapper apos-modal-filters-wrapper--right">
      {# Search #}
      <div class="apos-modal-filters-search" apos-modal-filters-search>
        {# we need data.options.label & pluralLabel #} {{ fields.string('search-' + data.options.name, 'Search ' + data.options.pluralLabel
        + '...', filters.q or '' ) }}
      </div>
    </div>
  </div>
  {% include "manageSelectEverything.html" %}
{%- endmacro -%}
